import 'package:flutter/material.dart';
import 'package:mi_mang_flutter/widget/ui/text_field_normal.dart';

/// 左侧文本,右侧为文本框的item
class TextFieldItem extends StatelessWidget {
  final TextEditingController controller;

  final FocusNode? focusNode;

  /// 左侧标题文本
  final String title;

  /// 左侧标题样式
  final TextStyle? titleStyle;

  /// 左侧文本对齐方式
  final TextAlign titleTextAlign;

  /// 提示文本内容
  final String hintText;

  /// 提示文本样式
  final TextStyle? hintStyle;

  /// 输入框文本样式
  final TextStyle? contentStyle;

  /// 文本框内容对齐微调
  final EdgeInsetsGeometry contentPadding;

  /// 运行文本框输入最大长度
  final int maxLength;

  /// 是否自动聚焦，默认是false。
  final bool autoFocus;

  /// 是否启用文本框输入
  final bool? enabled;

  /// 是否是密码输入
  final bool isInputPwd;

  /// TextField成为焦点时显示的键盘类型
  final TextInputType keyboardType;

  /// 右侧文本框距左侧宽度
  final double spacing;

  /// 左侧文本最小宽度
  final double minWidth;

  /// 外边距
  final EdgeInsets padding;

  /// 提交事件
  final ValueChanged<String>? onSubmitted;

  /// 编辑完成事件
  final VoidCallback? onEditingComplete;

  final String? star;

  TextFieldItem({
    Key? key,
    required this.controller,
    this.focusNode,
    this.title = "",
    this.titleStyle,
    this.titleTextAlign = TextAlign.right,
    this.hintText = "",
    this.hintStyle,
    this.contentStyle,
    this.contentPadding = const EdgeInsets.only(bottom: 5.0),
    this.maxLength = 16,
    this.autoFocus = false,
    this.enabled,
    this.isInputPwd = false,
    this.keyboardType = TextInputType.text,
    this.spacing = 15.0,
    this.minWidth = 75.0,
    this.onSubmitted,
    this.onEditingComplete,
    this.padding = const EdgeInsets.only(left: 15.0, right: 15.0),
    this.star,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 45.0,
      width: double.infinity,
      padding: this.padding,
      decoration: BoxDecoration(
        color: Colors.white,
        border: Border(
          bottom: Divider.createBorderSide(context,
              color: Divider().color, width: 0.5),
        ),
      ),
      child: TextFieldNormal(
        controller: this.controller,
        focusNode: this.focusNode,
        title: this.title,
        titleStyle: this.titleStyle,
        titleTextAlign: this.titleTextAlign,
        hintText: this.hintText,
        hintStyle: this.hintStyle,
        contentStyle: this.contentStyle,
        contentPadding: this.contentPadding,
        maxLength: this.maxLength,
        autoFocus: this.autoFocus,
        enabled: this.enabled,
        isInputPwd: this.isInputPwd,
        keyboardType: this.keyboardType,
        spacing: this.spacing,
        minWidth: this.minWidth,
        onSubmitted: this.onSubmitted,
        onEditingComplete: this.onEditingComplete,
      ),
    );
  }
}
